<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>localstoragw</title>
</head>
<body>
<div id="result"></div>
<div id="key"></div>
<div id="sessionls"></div>
</body>
<script>
    /*localStorage.sitename="MidnightSun";*/
    document.getElementById("result").innerHTML = "网站名：" + localStorage.name;
    localStorage.removeItem("sitename");//删除
    localStorage.setItem("name","hly");
    //localStorage.clear();//删除所有数据
    localStorage.key(1);//得到某个索引的key
    document.getElementById('key').innerHTML ="key:"+ localStorage.key(1);
    //关闭浏览器后会被删除
    sessionStorage.setItem("age","100");
    document.getElementById("sessionls").innerHTML = "sessionStorage："+sessionStorage.getItem("age");



</script>
</html>